package cn.ld.modules.demo.test.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import cn.ld.common.api.vo.Result;
import cn.ld.common.aspect.annotation.AutoLog;
import cn.ld.common.system.base.controller.LdController;
import cn.ld.modules.demo.test.entity.LdDemo;
import cn.ld.modules.demo.test.service.ILdDemoService;
import cn.ld.modules.demo.test.service.ILdDynamicDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 动态数据源测试
 * @Author: zyf
 * @Date:2020-04-21
 */
@Slf4j
@Tag(name = "动态数据源测试")
@RestController
@RequestMapping("/test/dynamic")
public class LdDynamicDataController extends LdController<LdDemo, ILdDemoService> {

    @Autowired
    private ILdDynamicDataService ldDynamicDataService;


    /**
     * 动态切换数据源

     * @return
     */
    @PostMapping(value = "/test1")
    @AutoLog(value = "动态切换数据源")
    @Operation(summary = "动态切换数据源")
    public Result<List<LdDemo>> selectSpelByKey(@RequestParam(required = false) String dsName) {
        List<LdDemo> list = ldDynamicDataService.selectSpelByKey(dsName);
        return Result.OK(list);
    }


}
